package com.example.fmgidsprototype.webservice;

import com.example.fmgidsprototype.R;
import android.accounts.Account;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class n_cst_adapter_account extends ArrayAdapter<Account> {
private Account[] inv_accounts;
	
	public n_cst_adapter_account(Context anv_context, Account[] anv_accounts)
	{
		super(anv_context, R.layout.activity_account_row, anv_accounts);
		inv_accounts = anv_accounts;
	}
	/*
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if(inv_accounts.length > 0){
			return inv_accounts.length;
		}
		else
		{
			return 0;
		}
	}

	@Override
	public Account getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
*/
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View lnv_row_view = convertView;
		
		if (lnv_row_view == null)
		{
			LayoutInflater lnv_inflator = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			
			lnv_row_view = lnv_inflator.inflate(R.layout.activity_account_row, parent, false);
			TextView luo_text_box = (TextView) lnv_row_view.findViewById(R.id.sle_account);
		
			Account lnv_account = this.inv_accounts[position];
			
			n_cst_view_holder lnv_view_holder = new n_cst_view_holder();
			
			lnv_view_holder.iuo_text_box = luo_text_box;
			lnv_view_holder.iuo_text_box.setTag(lnv_account);
			
			lnv_row_view.setTag(lnv_view_holder);
		}
		
		n_cst_view_holder lnv_view_holder = (n_cst_view_holder) lnv_row_view.getTag();
		
		String ls_account_name = ((Account) lnv_view_holder.iuo_text_box.getTag()).name;
		
		lnv_view_holder.iuo_text_box.setText(ls_account_name);

		return lnv_row_view;
	}
	
	private static class n_cst_view_holder
	{
		public TextView iuo_text_box;
	}

}
